package com.usian.behavior.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.usian.api.behavior.ApLikesBehaviorControllerApi;
import com.usian.behavior.service.ApLikesBehaviorService;
import com.usian.model.behavior.dtos.LikesBehaviorDto;
import com.usian.model.behavior.pojos.ApLikesBehavior;
import com.usian.model.common.dtos.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description:
 * @Auther:ASS
 * @Date:2023/3/2 18:45
 */

@RestController
@RequestMapping("/api/v1/likes_behavior")
public class ApLikesBehaviorController implements ApLikesBehaviorControllerApi {

    @Autowired
   private ApLikesBehaviorService apLikesBehaviorService;

    /**
     * 保存点赞行为
     *
     * @param dto
     * @return
     */
    @Override
    public ResponseResult like(LikesBehaviorDto dto) {
        return apLikesBehaviorService.like(dto);
    }

    /**
     * 根据行为实体id和文章id查询点赞行为
     * article 远程调用查询用户点赞行为
     * @param articleId
     * @param entryId
     * @param
     * @return
     */
    @Override
    @GetMapping("/findLike/{entryId}/{articleId}")
    public ApLikesBehavior findLike(@PathVariable Integer entryId,
                                    @PathVariable Long articleId) {

        //查询
        ApLikesBehavior apLikesBehavior = apLikesBehaviorService.getOne(Wrappers.<ApLikesBehavior>lambdaQuery().
                                    eq(ApLikesBehavior::getArticleId, articleId).eq(ApLikesBehavior::getEntryId, entryId));
        return apLikesBehavior;
    }
}
